//
//  MainPosterCollectionViewCell.m
//  项目1 CLCMovie
//
//  Created by huiwenjiaoyu on 15/7/24.
//  Copyright (c) 2015年 CLC. All rights reserved.
//

#import "MainPosterCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "UIViewExt.h"
#import "PosterDetailView.h"
#define kWidth  [UIScreen mainScreen].bounds.size.width
#define kHieght [UIScreen mainScreen].bounds.size.height

@implementation MainPosterCollectionViewCell
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        [self _creatSubview];

        
    }
    return self;
}

#pragma mark - CreatSubview

- (void)_creatSubview
{
    
    _mainPoster = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height)];
    [self.contentView addSubview:_mainPoster];
    
    NSArray* view = [[NSBundle mainBundle] loadNibNamed:@"PosterDetailView" owner:self options:nil];
    _detailView = [view lastObject];
    
    _detailView.frame = CGRectMake(0, 0, kWidth*3/4, self.height);
    [self.contentView addSubview:_detailView];
}




- (void)setIndex:(NSInteger)index
{
    _index = index;
    [self setNeedsLayout];
}

#pragma mark - DataSend

- (void)setModal:(HomeModal *)modal
{
    _modal = modal;
    self.detailView.homemodal = _modal;
    
    [self setNeedsLayout];
    
}


- (void)layoutSubviews{
    [super layoutSubviews];
    

    NSString* str = [_modal.images valueForKey:@"large"];
    [_mainPoster sd_setImageWithURL:[NSURL URLWithString:str]];
//    _detailView.homemodal = _modal;

    if(_isDetail)
    {
        _mainPoster.hidden = YES;
        _detailView.hidden = NO;
    }
    else
    {
        _mainPoster.hidden = NO;
        _detailView.hidden = YES;
    }
    
}

#pragma mark - flipCell
- (void)flipCell
{
    [self flipView:self];
    _mainPoster.hidden =! _mainPoster.hidden;
    _detailView.hidden =! _detailView.hidden;

}

- (void)flipView:(UIView*)view
{
    UIViewAnimationOptions option = _isDetail?UIViewAnimationOptionTransitionFlipFromLeft:UIViewAnimationOptionTransitionFlipFromRight;
    
    
    //翻转指令语句
    [UIView transitionWithView:view duration:.1 options:option animations:nil completion:nil];
}











@end
